type name = string
type age = int
type adress = string 
type telephone = int
type contact = (name * age * adress * telephone)
type agenda = contact list


let rec exist x list = match list with  
    [] -> false
  |e::l -> if e=x then 
      true 
    else 
      exist x l;;

exist 2 [2;3];;

let rec add_list x list = match list with 
    [] -> x::[]
  |e::l when x<e -> x::e::l
  |e::l when x=e -> list 
  |e::l -> e::add_list x l;;

add_list 2 [1;3;4];;


let rec remove_list x list = match list with 
    [] -> []
  |e::l ->
    if e<x then 
      e::remove_list x l 
    else 
      if e=x then 
	l
      else 
	x::e::l;;

remove_list 2 [2;3;4];;

let rec map fonction list = match list with 
    [] -> []
  |e::l -> fonction e::map fonction l;;

map (print_int) [1;2;3;4;5];;


let rec iter fonction list = match list with 
    [] -> ()
  |e::l ->
    begin
      fonction e; 
      iter fonction l
    end;;
    
iter (print_int) [1;2;3;4;5];;

let rec for_all fonction list = match list with 
    [] -> true
  |e::l ->
    begin 
      if fonction e = true then
	for_all fonction l
      else 
	false 
    end ;;

for_all (function x -> x=0) [0;0;0;1;0;0];;


let upper_case lettre = 
  let maj = int_of_char lettre in 
  if maj>96 && maj<123 then 
    char_of_int (maj-32)
  else
    lettre;;
	

let lower_case lettre = 
  let min = int_of_char lettre in 
  if min>64 && min<91 then 
    char_of_int (min+32)
  else
    lettre;;


let string_of_char c = String.make 1 c;;


let string_apply fonction mot = 
  let length = (String.length mot) -1 in
  let rec apply i mot string = match i with 
      i when i = length -> string^(string_of_char(fonction mot.[i]))
    |i -> apply (i+1) mot (string^(string_of_char(fonction mot.[i])))
  in apply 0 mot "";;


